package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.client.enums.TriggerStrategy;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalErrorConsts;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

public class AccountWhiteListAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
        //卡级白名单
        KiteAttr cardWhiteListAttr = inst.getAttr("200004022");
        //白名单号码
        KiteAttr whiteListNbrAttr = inst.getAttr("200003695");
        if (!"H".equals(attr.getShowType()) && !"H".equals(cardWhiteListAttr.getShowType()) && !"E"
            .equals(attr.getShowType()) && !"E".equals(cardWhiteListAttr.getShowType())) {
            whiteListNbrAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            whiteListNbrAttr.setIsNull(KeyConsts.IFTRUE_F);
        }
    }

    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        if (KiteStringUtils.isEmpty(inst.getAttrValue("200004022")) || KiteStringUtils.isEmpty(value)) {
            return;
        }
        if (!"100006427".equals(value) && !"100006427".equals(inst.getAttrValue("200004022"))) {
            LocalErrorConsts.UPLOAD_FILE_ERR_604.throwOut();
        }
    }
}
